package com.zxx.flowerstore.service.impl;

import com.zxx.flowerstore.dao.FlowerProvincesMapper;
import com.zxx.flowerstore.entity.FlowerProvinces;
import com.zxx.flowerstore.entity.FlowerProvincesExample;
import com.zxx.flowerstore.entity.constant.MagicConstant;
import com.zxx.flowerstore.service.ProvinceService;
import com.zxx.flowerstore.utils.common.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**、
 * @ClassName ProvinceServiceImpl
 * @Author zhanghaorui
 * @Date 2021/3/30 10:28 上午
 * @Description ProvinceServiceImpl
 * @Version 1.0
 */
@Service
public class ProvinceServiceImpl implements ProvinceService {

    @Autowired
    private FlowerProvincesMapper flowerProvincesMapper;

    @Override
    public Result selectProvinces(FlowerProvinces flowerProvinces) {
        FlowerProvincesExample flowerProvincesExample = new FlowerProvincesExample();
        if (flowerProvinces != null && flowerProvinces.getCode()!=null) {
            flowerProvincesExample.createCriteria().andParentCodeEqualTo(flowerProvinces.getCode().toString());
            List<FlowerProvinces> flowerProvincesList = flowerProvincesMapper.selectByExample(flowerProvincesExample);
            return Result.success(flowerProvincesList);
        }
        flowerProvincesExample.createCriteria().andLevelEqualTo(MagicConstant.PROVINCE);
        List<FlowerProvinces> flowerProvincesList = flowerProvincesMapper.selectByExample(flowerProvincesExample);
        return Result.success(flowerProvincesList);
    }
}
